package luanluan.events 
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	/**
	 * ...
	 * @author luanluan
	 */
	public class EventCenter 
	{
		private static var _event:EventDispatcher = new EventDispatcher();
		
		/**
		 * Dispatches an event into the event flow. The event target is the EventDispatcher 
		 * object upon which the dispatchEvent() method is called.
		 * @param	event	The Event object that is dispatched into the event flow.
		 *   If the event is being redispatched, a clone of the event is created automatically.
		 *   After an event is dispatched, its target property cannot be changed, so you
		 *   must create a new copy of the event for redispatching to work.
		 * @return	A value of true if the event was successfully dispatched. A value of false indicates failure or that preventDefault() was called 
		 *   on the event.
		 * @langversion	3.0
		 * @playerversion	Flash 9
		 * @playerversion	Lite 4
		 * @throws	Error The event dispatch recursion limit has been reached.
		 */
		public static function dispatchEvent (event:Event) : Boolean
		{
			return _event.dispatchEvent(event);
		}
		
		/**
		 * Checks whether the EventDispatcher object has any listeners registered for a specific type 
		 * of event. This allows you to determine where an EventDispatcher object has altered
		 * handling of an event type in the event flow hierarchy. To determine whether a specific
		 * event type actually triggers an event listener, use willTrigger().
		 * 
		 *   The difference between hasEventListener() and willTrigger() 
		 * is that hasEventListener() examines only the object to 
		 * which it belongs, whereas willTrigger() examines the entire 
		 * event flow for the event specified by the type parameter.
		 * 
		 *   When hasEventListener() is called from a LoaderInfo object, only the 
		 * listeners that the caller can access are considered.
		 * @param	type	The type of event.
		 * @return	A value of true if a listener of the specified type is registered; 
		 *   false otherwise.
		 * @langversion	3.0
		 * @playerversion	Flash 9
		 * @playerversion	Lite 4
		 */
		public static function addEventListener (type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false) : void
		{
			_event.addEventListener(type , listener , useCapture , priority , useWeakReference);
		}
		
		/**
		 * Removes a listener from the EventDispatcher object. If there is no matching listener registered with the EventDispatcher object, a call to this method has no effect.
		 * @param	type	The type of event.
		 * @param	listener	The listener object to remove.
		 * @param	useCapture	Specifies whether the listener was registered for the capture phase or the 
		 *   target and bubbling phases. If the listener was registered for both the capture phase and the
		 *   target and bubbling phases, two calls to removeEventListener() are required 
		 *   to remove both, one call with useCapture() set to true, and another 
		 *   call with useCapture() set to false.
		 * @langversion	3.0
		 * @playerversion	Flash 9
		 * @playerversion	Lite 4
		 */
		public static function removeEventListener (type:String, listener:Function, useCapture:Boolean = false) : void
		{
			_event.removeEventListener(type , listener , useCapture);
		}
	}

}